package com.thd.framework.basic.utils;


import com.thd.framework.basic.BasicException;

import java.util.List;
import java.util.Set;

/**
 * com.lenovo.dqm.common.utils.MyAssertUtils
 *
 * @author: wanglei62
 * @DATE: 2021/7/27 15:11
 **/
public class AssertUtils {
    public static void isTrue(boolean expression, String message) {
        if (!expression) {
            BasicException.throwMyException(message);
        }
    }

    public static void isFalse(boolean expression, String message) {
        if (!expression) {
            BasicException.throwMyException(message);
        }
    }

    public static void isNull(Object object, String message) {
        if (null != object) {
            BasicException.throwMyException(message);
        }
    }



    public static void isNotNull(Object object, String message) {
        if (null == object) {
            BasicException.throwMyException(message);
        }
    }




    public static void listIsEmpty(List l , String message){
        AssertUtils.isNotNull(l,message);
        if(l.size() > 0){
            BasicException.throwMyException(message);
        }
    }





    public static void setIsNotEmpty(Set l , String message){
        if(null == l || l.size() <= 0){
            BasicException.throwMyException(message);
        }
    }

    public static void listIsNotEmpty(List l , String message){
        if(null == l || l.size() <= 0){
            BasicException.throwMyException(message);
        }
    }

    public static void stringEquals(String str , String v , String message){
        AssertUtils.stringIsNotEmpty(str,"Parameter can not be empty");

        AssertUtils.stringIsNotEmpty(v,"Parameter can not be empty");
        if(!v.equals(str)){
            BasicException.throwMyException(message);
        }
    }

    public static void stringIsEmpty(String str , String message){
        if(StringUtils.isNotEmpty(str)){
            BasicException.throwMyException(message);
        }
    }




    public static void stringIsNotEmpty(String str , String message){
        if(StringUtils.isEmpty(str)){
            BasicException.throwMyException(message);
        }
    }

    public static void stringMaxLen(String str, int maxLen , String message){
        AssertUtils.stringIsNotEmpty(str,"Parameter can not be empty");
        if(maxLen < str.length()){
            BasicException.throwMyException(message);
        }
    }

    public static void integerLt(Integer no , Integer compare, String message){
        if(no.compareTo(compare) >= 0){
            BasicException.throwMyException(message);
        }
    }

    public static void integerLtOrEq(Integer no , Integer compare, String message){
        if(no.compareTo(compare) > 0){
            BasicException.throwMyException(message);
        }
    }

    public static void integerEq(Integer no , Integer compare, String message){
        if( !(no.compareTo(compare) == 0)){
            BasicException.throwMyException(message);
        }
    }

    public static void integerGt(Integer no , Integer compare, String message){
        if( no.compareTo(compare) >= 0){
            BasicException.throwMyException(message);
        }
    }

    public static void integerGtOrEq(Integer no , Integer compare, String message){
        if( no.compareTo(compare) > 0){
            BasicException.throwMyException(message);
        }
    }


}
